package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployeeService;
import com.sky.vo.EmployeeLoginVO;
import com.sky.vo.EmployeeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Api(tags = "员工管理")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("员工登录")
    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
        log.info("员工登录，employeeLoginDTO：{}", employeeLoginDTO);
        EmployeeLoginVO employeeLoginVO = employeeService.login(employeeLoginDTO);
        return Result.success(employeeLoginVO);
    }


    /**
     * 退出
     *
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation("员工退出")
    public Result<String> logout() {
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增员工")
    public Result<String> addEmployee(@RequestBody EmployeeDTO employeeDTO) {
        log.info("添加员工，employeeDTO：{}", employeeDTO);
        employeeService.addEmployee(employeeDTO);
        return Result.success(MessageConstant.ADD_SUCCESS);
    }

    @GetMapping("/page")
    @ApiOperation("员工列表查询")
    public Result<PageResult<EmployeeVO>> getPageList(EmployeePageQueryDTO employeePageQueryDTO){
        log.info("员工列表查询，employeePageQueryDTO：{}", employeePageQueryDTO);
        return Result.success(employeeService.getPageList(employeePageQueryDTO));
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询员工")
    public Result<EmployeeVO> getEmployee(@PathVariable Long id){
        log.info("员工信息查询，id：{}", id);
        return Result.success(employeeService.getEmployeeById(id));
    }

    @PutMapping
    @ApiOperation("员工信息修改")
    public Result<String> modifyEmployee(@RequestBody EmployeeDTO employeeDTO){
        log.info("员工信息修改，employeeDTO：{}", employeeDTO);
        employeeService.modifyEmployeeById(employeeDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("员工账号禁用")
    public Result<String> disableOrEnableEmployee(@PathVariable Integer status, Long id){
        log.warn("启用或禁用, status:{}, id:{}", status, id);
        employeeService.disableOrEnableEmpStatus(status, id);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }



}
